﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iReaper.IndexBuilder.XmlSource
{
    class CNTechnetParser : IIndexParser
    {
        #region IIndexParser Members

        public Channel Parse(System.IO.TextReader txtReader)
        {
            Sgml.SgmlReader reader = new Sgml.SgmlReader();
            reader.InputStream = txtReader;

            while (reader.ReadToFollowing("tabel"))
            {
                if (reader.GetAttribute("id") == "HeadlinesGrid")
                {
                    // get its tbody sub node.
                    if (reader.ReadToFollowing("tbody"))
                    {
                        XmlReader channelReader = reader.ReadSubtree();
                        Channel channel;
                        ParseChannelTable(channelReader, out channel);
                        return channel;
                    }
                }
            }

            return null;
        }

        #endregion

        private void ParseChannelTable(XmlReader reader, out Channel channel)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            channel = new Channel();
            while (reader.ReadToFollowing("tr"))
            {
                
                // DateTime
                // Url
                // Category
                // Level
                // Author
                // meida, type=application/pdf 
                // media, 
            }
        }

        
    }
}
